const { existsSync, mkdirSync } = require('fs')

const AVATAR_PATH = './uploads/avatar/'
const PICTURE_PATH = './uploads/picture/'

async function checkFile() {
  const uploads = await existsSync('./uploads')
  if (!uploads) {
    await mkdirSync('./uploads')
  }
  for (const path of [AVATAR_PATH, PICTURE_PATH]) {
    const flag = await existsSync(path)
    if (!flag) {
      await mkdirSync(path)
    }
  }
}
checkFile()

// mkdirSync('./uploads')

function resAvatarPath() {
  const date = new Date()
  const filename = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
  return AVATAR_PATH + filename
}

function resPicturePath() {
  const date = new Date()
  const filename = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
  return PICTURE_PATH + filename
}

module.exports = {
  resAvatarPath,
  resPicturePath,
}
